package com.funtl.screw.admin.controller;

import cn.hutool.json.JSONArray;
import com.funtl.screw.admin.entity.SysRouteConf;
import com.funtl.screw.admin.service.SysRouteConfService;
import com.funtl.screw.common.core.util.ResponseResult;
import com.funtl.screw.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 路由
 *
 * @author Lusifer
 * @since 2018-11-06 10:17:18
 */
@RestController
@AllArgsConstructor
@RequestMapping("/route")
@Api(value = "route", tags = "动态路由管理模块")
public class SysRouteConfController {

    private final SysRouteConfService sysRouteConfService;

    /**
     * 获取当前定义的路由信息
     */
    @GetMapping
    public ResponseResult<List<SysRouteConf>> listRoutes() {
        return ResponseResult.ok(sysRouteConfService.list());
    }

    /**
     * 修改路由
     *
     * @param routes 路由定义
     */
    @SysLog("修改路由")
    @PutMapping
    public ResponseResult<Mono<Void>> updateRoutes(@RequestBody JSONArray routes) {
        return ResponseResult.ok(sysRouteConfService.updateRoutes(routes));
    }

}
